import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/home/show',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../components/login/Login.vue'),
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../components/home/Home.vue'),
    children: [
      {
        path: 'show',
        name: 'show',
        component: () => import('../components/show/Show.vue'),
        meta: { path: '/home/show', title: '工作台' },
      },
      {
        path: 'roomList',
        name: 'roomList',
        component: () => import('../components/roomList/RoomList.vue'),
        meta: { path: '/home/roomList', title: '房间列表' },
      },
      {
        path: 'roomAdd',
        name: 'roomAdd',
        component: () => import('../components/roomAdd/RoomAdd.vue'),
        meta: { path: '/home/roomAdd', title: '房间上新' },
      },
      {
        path: 'dinnerList',
        name: 'dinnerList',
        component: () => import('../components/dinnerList/DinnerList.vue'),
        meta: { path: '/home/dinnerList', title: '餐品列表' },
      },
      {
        path: 'dinnerAdd',
        name: 'dinnerAdd',
        component: () => import('../components/dinnerAdd/DinnerAdd.vue'),
        meta: { path: '/home/dinnerAdd', title: '餐品上新' },
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('../components/order/Order.vue'),
        meta: { path: '/home/order', title: '订单管理' },
      },
      {
        path: 'comment',
        name: 'comment',
        component: () => import('../components/comment/Comment.vue'),
        meta: { path: '/home/comment', title: '评论管理' },
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('../components/user/User.vue'),
        meta: { path: '/home/user', title: '用户管理' },
      },
      {
        path: 'roomEditor',
        name: 'roomEditor',
        component: () => import('../components/roomEditor/RoomEditor.vue'),
      },
      {
        path: 'dinnerEditor',
        name: 'dinnerEditor',
        component: () => import('../components/dinnerEditor/DinnerEditor.vue'),
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../components/login/Login.vue'),
  },
]
const router = createRouter({
  history: createWebHistory(),
  routes: routes,
  linkExactActiveClass: 'active',
})

router.beforeEach((to, from, next) => {
  // let token = localStorage.getItem('token')
  // if (token) {
  //   next()
  // } else {
  //   if (to.path == '/login') {
  //     next()
  //   } else {
  //     router.push('/login')
  //   }
  // }
  next()
})
export default router
